<template>
	<view class="container">

		<scroll-view class="noticeList" refresher-enabled :refresher-triggered="isRefreshing"  @refresherrefresh="onRefresh" @scrolltolower="onLoadMore" scroll-y>
		    <view class="notice-item" v-for="(item, index) in noticeList" :key="index">
			  <view class="notice-top">
				  <text class="notice-name fl">{{ item.noticeTitle }}</text>
				  <text class="fr">
					<p class="weui-text__primary" v-if="item.noticeType == 1" style="color: #ffba00;">{{ getDictsLable(item.noticeType) }}</p>
					<p class="weui-text__primary" v-if="item.noticeType == 2" style="color: #13ce66;">{{ getDictsLable(item.noticeType) }}</p>
				  </text>
			  </view>
		      <view class="notice-box">
				  <view class="notice-details" v-html="item.noticeContent"> </view>

		      </view>
		      
		    </view>
		  </scroll-view>

	</view>
</template>

<script>
import { getDict } from '@/api/system/dict'
import { getNotice } from '@/api/system/notice'

export default {
	
	
	data() {
		return {
			isRefreshing: false,
            page: '1',
			pageSize:'10',
			searchValue:'',
			colorIndex: 1,
			activeColor: '#319efc',
			noticeData: [],
			noticeList: [],
			    
		}
	},

	// 页面加载时触发（接收参数）
	onLoad(options) {
		this.dictLoadData() // 调用字典初始化方法
		this.getList(); // 调用初始化方法
	},
	methods: {
		onRefresh() {
		  uni.showLoading({ title: '刷新中' });
		  this.isRefreshing = true;
		  this.page = 1;
		  this.getList()
			.catch(() => {})
			.finally(() => {
			  this.isRefreshing = false;
			  uni.hideLoading();
			});
		},

		dictLoadData() {
		  getDict('sys_notice_type').then(response => {
			console.log(response)
			if(response.code==200){
				this.noticeData = response.data
		
				
			}else{
				uni.showToast({
				  title:response.msg,
				  icon:'none'
				})
			}
			
		  })
		},
		getDictsLable(value){
		  // 方法1：直接查找
		  const result = this.noticeData.find((item) => item.dictValue === value)?.dictLabel;
		  return result || ''; // 添加默认值测试;
		
		},
		getList() {
		  return getNotice({ pageNum: this.page, pageSize: this.pageSize })
			.then((response) => {
			  if (this.page = 1) {
				this.noticeList = [];
			  }
			  this.noticeList = this.noticeList.concat(response.rows);
			});
		},
		onLoadMore() {
		   this.page++;
		   this.getList();
	    },
	
	
		
	}
}
</script>

<style scoped lang="scss">
.fl{
    float: left;
}
.fr{
    float: right;
}
.clear{
	clear: both;
}
/* 保持原有样式不变 */
.container {
   display: flex;
   flex-direction: column; /* 垂直排列子元素 */
   height: 100vh; /* 关键：容器高度充满视窗 */
   background-color: #f2f2f2;
}

.noticeSearch{
   background-color: #ffffff;
}

.noticeList {
   padding: 0 20rpx;
   width: 100%;
   flex: 1; /* 关键：占据剩余空间 */
   overflow-y: auto; /* 确保滚动生效 */
   
   
   
   .notice-item {
      margin-top: 20rpx;
      padding: 30rpx;
      border-radius: 20rpx;
      box-shadow: 0 2px 16rpx rgba(0, 0, 0, 0.1);
      background-color: #ffffff;
   }
   
   .notice-top {
   	  width: 100%;
   	  height: 60rpx;
   	  line-height: 60rpx;
   	  border-bottom: 1rpx solid #e6e6e6;
   }
   
   .notice-box {
      margin-bottom: 10rpx;
      padding-top: 10rpx;
     
     .notice-name{
		 margin-top: 20rpx;
   	     font-size: 30rpx;
   	     font-weight: bold;
     }
	 .notice-details{
		 margin-top: 20rpx;
		 color: #777777;
		 font-size: 26rpx;
	 }
   }
}




.submit-btn {
	background: #007AFF;
	color: white;
	border-radius: 8rpx;
}
</style>